/**
 * 定义方法直接暴露出去方法名即可 再main.js已经注册了 
 * 
 * 类似于angular管道
 */
var padDate = function(value) {
	return value < 10 ? '0' + value : value;
};

export function nullToNumber(value) {
	if (value == null || value == "" || value.length == 0) {
		return 0
	}
	return null
}

export function formatDate(value) {
	if (value == null || value == "" || value.length == 0) {
		return "--"
	}
	var date = new Date(value);
	var year = date.getFullYear();
	var month = padDate(date.getMonth() + 1);
	var day = padDate(date.getDate());
	var hours = padDate(date.getHours());
	var minutes = padDate(date.getMinutes());
	var seconds = padDate(date.getSeconds());
	return year + '-' + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds
}
export function formatDateDay(value) {
	if (value == null || value == "" || value.length == 0) {
		return "--"
	}
	var date = new Date(value);
	var day = padDate(date.getDate());
	var hours = padDate(date.getHours());
	var minutes = padDate(date.getMinutes());
	var seconds = padDate(date.getSeconds());
	return day + "日" + hours + ":" + minutes + ":" + seconds
}
export function formatDateHHss(value) {
	if (value == null || value == "" || value.length == 0) {
		return "--"
	}
	var date = new Date(value);
	var date1 = new Date();
	if (date1.getDate() >= date.getDate() + 1) {
		var year = padDate(date.getMonth() + 1);
		var day = padDate(date.getDate());
		return date.getFullYear() + "/" + year + "/" + day
	} else {
		var minutes = padDate(date.getMinutes());
		var hours = padDate(date.getHours());
		var seconds = padDate(date.getSeconds());
		return hours + ":" + minutes + ":" + seconds
	}

}
export function formatDateYYYYMMdd(value) {
	if (value == null || value == "" || value.length == 0) {
		return "--"
	}
	var date = new Date(value);
	var date1 = new Date();
	date1.setDate(date1.getDate() - 1)
	var year = date.getFullYear();
	var month = padDate(date.getMonth() + 1);
	var day = padDate(date.getDate());
	return year + '-' + month + '-' + day
}


export function formatValue(value) {
	if (value == null || value == "") {
		return
	}
	return value.content
}
export function formatTime(value) {
	if (value == null || value == "") {
		return
	}
	return formatDateHHss(value.createTime)
}

export function formatPhoneNum(value){
	if (value == null || value == "") {
		return
	}
	let mphone = value.substring(0, 3) + ' **** ' + value.substring(7);
	return mphone;
}

export function formatBankCardNum(value){
	if (value == null || value == "") {
		return
	}
	let bankCardNo = value.substring(0, 4) + " " + value.substring(4, 8) + ' **** ' + value.substring(12);
	return bankCardNo;
}

export function setMorKm(m){
    var n=''
    if(m){
        if (m >= 1000) {
            n = (m / 1000).toFixed(2) + 'km'
        } else {
            n = m + 'm'
        }
    }else{
        n = '-m'
    }
    return n
}